import 'package:flutter_emoji/flutter_emoji.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/emojiOne/EmojiOne.dart';
import 'package:im_app/im/emojiOne/EmojiOneInfoes.dart';
import 'package:im_app/im/util/ImRichTextUtil.dart';

void main() {
  test("split test", () async {
    String str = "￼e{record_button}￼e{aquarius}￼e{ophiuchus}￼e{high_brightness}￼e{high_brightness}";
    List<String> strList = ImRichTextUtil.split(str);
    for (var span in strList) {
      print("span: ${span}");
    }
  });

  test("split test", () async {
    String str = "13124￼e{record_button}￼e{aquarius}￼e{ophiuchus}￼e{high_brightness}￼e{high_brightness}134214";
    List<String> strList = ImRichTextUtil.split(str);
    for (var span in strList) {
      print("span: ${span}");
    }
  });

  test("select span", () async {
    String str = "13124134214";
    List<String> strList = ImRichTextUtil.split(str);
    for (var span in strList) {
      print("span: ${span}");
    }
  });

  test("split select", () async {
    String str = "213131￼e{aquarius}￼e{ophiuchus}342523";
    List<String> strList = ImRichTextUtil.split(str);
    await EmojiOneInfoes.getInstance().loadData();
    var spans = <Object>[];
    for (var str in strList) {
      if (str.startsWith(ImRichTextUtil.SPLIT)) {
        var unicode = str.substring(3, str.length-1);
        var emoji = EmojiOneInfoes.getInstance().getByUnicodeOrShortName(unicode);
        if (emoji != null) {
          spans.add(emoji);
        }
      } else {
        spans.add(str);
      }
    }

    List<Object> selectSpans = ImRichTextUtil.getSelectSpan(spans, 6, 9);
    for (var obj in selectSpans) {
      if (obj is String) {
        print("select span: ${obj.toString()}");
      } else {
        var str = ImRichTextUtil.emojiToString(obj as EmojiOne);
        print("select span2: ${str}");
      }
    }
  });

  test("emoji paths", () async {
    await EmojiOneInfoes.getInstance().loadData();
    // people  nature food activity travel objects symbols flags
    List<EmojiOne> emojiOneList = EmojiOneInfoes.getInstance().getAllEmojiOnes();
    var parser = EmojiParser();
    int total = 0;
    for (var emojiOne in emojiOneList) {
      var isExist = parser.hasName(emojiOne.shortname.substring(1, emojiOne.shortname.length-1));
      if (isExist) {
        print("emoji is not exist: ${emojiOne.shortname}");
        total ++;
      }
    }
    print('size： ${emojiOneList.length}, total: $total');
  });
}